<template>
 <div class="user_list pd_40">
   <div>
     <el-row :gutter="40">
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">用户名</span>
          <el-input
            placeholder="请输入"
            v-model.trim="tableData.nickname">
          </el-input>
        </div>
      </el-col>
    
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">登录时间</span>
          <el-date-picker
            v-model="dataTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="7">
        <div class="fsc">
          <span class="articlelist_lable">性别</span>
          <el-select v-model.trim="tableData.sex" placeholder="请选择">
            <el-option label="女" value="2"></el-option>
            <el-option label="男" value="1"></el-option>            
          </el-select>
        </div>
      </el-col>

      <el-col :span="7" class="mg_t20">
        <div class="fsc">
          <span class="articlelist_lable ">年龄</span>
          <el-select v-model="tableData.age" placeholder="请选择">
            <el-option
              v-for="item in optionsAge"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </div>
      </el-col>
      <!--<el-col class='mg_t20' :span="7">
        <div class="fsc">
          <span class="articlelist_lable">有无认证</span>
          <el-select placeholder="全部">
            <el-option label="有" value="1"></el-option>
            <el-option label="无" value="2"></el-option>
          </el-select>
        </div>
      </el-col>-->
      <el-col class='mg_t20' :span="7">
        <div class="fsc">
          <span class="articlelist_lable">身份</span>
          <el-select v-model.trim="tableData.expert" placeholder="请选择">
            <el-option label="普通" value="0"></el-option>
            <el-option label="达人" value="1"></el-option>
          </el-select>
        </div>
      </el-col>
     </el-row>
     <p class="articlelist_query fec">
      <el-button @click="reset">重置</el-button>
      <el-button @click="query" type="primary">查询</el-button>  
    </p>
   </div>
   <div>
     <el-table
      :data="tableList"
      style="width: 100%">
      <el-table-column
        prop="nickname"
        label="用户名"
        width="180">
      </el-table-column>
      <el-table-column
        label="ID"
        width="110">
        <template slot-scope="scope">
          <span>{{scope.row.id}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="sex"
        width="110"
        label="性别">
        <template slot-scope="scope">
          <span>{{scope.row.sex==1?'男':(scope.row.sex==''?'--':'女')}}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="address"
        width="200"
        label="所在地区">
      </el-table-column>
      <el-table-column
        width="150"
        label="年龄">
        <template slot-scope="scope">
          <span>{{scope.row.age==''?'--':scope.row.age}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        width="130"
        label="身份">
        <template slot-scope="scope">
          <span>{{scope.row.expert==0?'普通':'达人'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        width="100"
        label="有无认证">
      </el-table-column>
      <el-table-column
        width="150"
        label="身份备注">
        <template slot-scope="scope">
          <span>{{scope.row.expert==0?'--':scope.row.expert_text}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="num"
        align="center"
        width="110"
        label="第几次登录">
      </el-table-column>
      <el-table-column
        width="200"
        label="最近访问时间">
        <template slot-scope="scope">
          <span>{{getdates(scope.row.updatetime)}}</span>
          
        </template>
      </el-table-column>
    
      <el-table-column
        width="150"
        label="更多用户信息">
        <template slot-scope="scope">
          <el-button @click="addSee(scope.row)" type="success" size="small">查看</el-button>
        </template>
      </el-table-column>
      </el-table-column>
      <el-table-column
        prop="address"
        label="管理">
        <template slot-scope="scope">
          <el-button @click="administration(scope.row)" type="primary" size="small">管理</el-button>
        </template>
      </el-table-column>
    </el-table>
   </div>
  <div class="block fec mg_t30">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage4"
      :page-sizes="[10]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>

  <!--点击管理alert-->
  <el-dialog
    title="用户管理"
    :visible.sync="centerDialogVisible"
    width="600px"
    center>
    <div class="fbc fwrap">
      <div class="user_dialog_desc fbc w100">
        <p><span>用户名:</span><span class="mg_l15">{{dialog.nickname}}</span></p>
        <p><span>最近访问日期:</span><span class="mg_l15">{{getdates(dialog.updatetime)}}</span></p>
        <p><span>身份:</span><span class="mg_l15">{{dialog.expert==0?'普通':'达人'}}</span></p>
      </div>
      

      <div class="fbc mg_t30 w100">
        <el-button :type="index==1?'primary':''" :disabled="dialog.expert==1?true:false"  @click="diaButton(1)">设为达人</el-button>
        <el-button :type="index==2?'primary':''" :disabled="dialog.expert==0?true:false"  @click="diaButton(2)">取消达人</el-button>
        <el-button :type="index==3?'primary':''"  @click="diaButton(3)">禁言七天</el-button>
        <el-button :type="index==4?'primary':''"  @click="diaButton(4)">永久禁言</el-button>
        <el-button :type="index==5?'primary':''"  @click="diaButton(5)">解除禁言</el-button>
        <!--<el-button :type="index==4?'primary':''"  @click="index=4">设为管理员</el-button>-->
      </div>
      <div class="mg_t20">
        <textarea v-show="areaFlag" class="text_area" :placeholder="placeholder" v-model.trim="reason"  name="" id=""></textarea>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="centerDialogVisible=false">取消</el-button>
      <el-button size="small" type="primary" @click="determine()">确定</el-button>
    </span>
  </el-dialog>

  <!--查看用户信息alert-->
  <el-dialog
    title="更多用户信息"
    :visible.sync="moreUsermaAlert"
    width="30%"
    center>
    <div class="fbc fwrap">
      <div class="fbc w100">
        <p><span>用户名:</span><span class="mg_l15">{{detail.user_info.nickname}}</span></p>
        <p class="fsc"><span>图像</span><img class="user_img mg_l15" :src="detail.user_info.headurl" alt="做客"></p>
      </div>
      <div class="user_dialog_desc fbc w100">
        <p><span>地区:</span><span class="mg_l15">{{detail.user_info.address}}</span></p>
        <p><span>年龄:</span><span class="mg_l15">{{detail.user_info.age}}</span></p>
        <p><span>身份:</span><span class="mg_l15">{{detail.user_info.expert == 0?'普通':'达人'}}</span></p>
        <p><span>性别:</span><span class="mg_l15">{{detail.user_info.sex==1?'男':(detail.user_info.sex==0?'--':'女')}}</span></p>
      </div>
      <!--<div class="user_dialog_desc fbc w100">
        <p><span>姓名:</span><span class="mg_l15">刘德华</span></p>
        <p><span>身份证号码:</span><span class="mg_l15">341222199901042978</span></p>
        <p><span>电话验证:</span><span class="mg_l15">17620547902</span></p>
      </div>-->
      <div class="user_dialog_quan fbc w100">
        <p class="fcc column"><span>旅说</span><span class="mg_t10">{{detail.dynamic_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>想去看看</span><span class="mg_t10">{{detail.see_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>到此一游</span><span class="mg_t10">{{detail.visit_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>关注</span><span class="mg_t10">{{detail.follow_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>粉丝</span><span class="mg_t10">{{detail.fans_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>收藏</span><span class="mg_t10">{{detail.collection_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>评论</span><span class="mg_t10">{{detail.comment_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>评分</span><span class="mg_t10">{{detail.score_num}}</span><span class="mg_t20 c_green">查看</span></p>
        <p class="fcc column"><span>投诉</span><span class="mg_t10">{{detail.complain_num}}</span><span class="mg_t20 c_green">查看</span></p>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="moreUsermaAlert=false;">关闭</el-button>
    </span>
  </el-dialog>
 </div>

 
</template>
<script>
export default {
  data() {
    return {
      dataTime: [], // 查询时间
      reason: '',   // 管理内容原因
      areaFlag: true,   // dialog area 隐藏
      total: null,  // 总条数
      placeholder: '', // 弹窗textarea水印
      detail: {
        user_info: {},
      },
      optionsAge: [     //年龄选择
        {value: '10后',label: '10后' },        
        {value: '00后',label: '00后' },
        {value: '90后',label: '90后' },
        {value: '80后',label: '80后' },
        {value: '70后',label: '70后' },
        {value: '60后',label: '60后' },
        {value: '50后',label: '50后' },
        {value: '40后',label: '40后' },
      ],
      getdates: this.$utils.getdates,  //处理时间
      tableData: {
        nickname: '',
        sex: '',
        age: '',
        start: '',
        end: '',
        expert: '',
        page: 1,
      },
      tableList: [],  //列表数据
      dialog: {},

      index: 1,    //dialog里button
     
      currentPage4: 1,
      centerDialogVisible: false,
      moreUsermaAlert: false,

     
    }
  },
  created() {
    this.getList()  
  },
  watch: {
    'dataTime'(xin,jiu) {
       if(xin == null) {
        this.tableData.start = '';
        this.tableData.end = '';
      }
    }
  },
  methods: {
    getList() {          //获取列表
      let url = '/admin/user/user_list';
      let data = this.tableData;
      this.$request.post(url,data).then(res => {
        console.log(res)
        if(res.data.code == '0000') {
          this.tableList = res.data.data.list;
          this.total = res.data.data.page.total;
        }
      })
    },
    getDetail() {
      let url = '/admin/user/user_info';
      // let data = {user_id: };
      // this.$$request.post(url,data).then(res => {
      //   console.log(res)
      // })
    },
    determine() {
      let dialog = this.dialog;
      console.log(dialog);
      
      let is;
      let index = this.index;
      if(index == 1 ||index == 3 ||index == 4 ) {
        if(this.reason == '') {
          this.$message.error('请输入内容');
          return;
        }
      }
      
      if(index == 1) {
        is = 1
      }else if(index == 2) {
        is = 2
      }else if(index == 3) {
        is = 1
      }else if(index == 4) {
        is = 2
      }else if(index == 5) {
        is = 3
      }
      if(index == 1 || index == 2) {
        let url = "/admin/user/expert";
        let data = {expert_text: this.reason,is,user_id:dialog.id};
        this.$request.post(url,data).then( res => {
          if(res.data.code == '0000') {
            console.log(res)
            this.centerDialogVisible = false;
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.getList();
          }
        })
        return;
      };
      let url = '/admin/user/silent_time';
      let data = {user_id: dialog.id,silent_text: this.reason,is: is}
      this.$request.post(url,data).then( res => {
        if(res.data.code == '0000') {
          console.log(res)
          this.$message({
            type: 'success',
            message: '操作成功'
          })
          this.centerDialogVisible = false;
           this.getList();
        }else {
          this.$message.error('操作失败');
        }
        
      }).catch(err => {
        this.$message.error('操作失败');
      })

    },
    administration(row) {
      this.dialog = row;
      console.log(row)
      if(row.expert == 1) {
        this.index = 2
      }else {
        this.index = 1
      }
      if(this.index == 1) {
        this.placeholder = '输入达人身份备注信息';
        this.areaFlag = true;
        this.reason = '';
        
      }else if(this.index == 2) {
        this.reason = '';
        this.areaFlag = false;
      }else if(this.index == 3) {
        this.placeholder = '输入禁言7天原因';
        this.reason = '';
        this.areaFlag = true;
      }else if(this.index == 4) {
        this.placeholder = '输入永久禁言原因';
        this.reason = '';
        this.areaFlag = true;
      }else if(this.index == 5) {
        this.reason = '';
        this.areaFlag = false;
      }
      this.centerDialogVisible = true
    },
    diaButton(num) {
      this.index = num;
       if(this.index == 1) {
        this.placeholder = '输入达人身份备注信息';
        this.areaFlag = true;
        this.reason = '';
      }else if(this.index == 2) {
        this.reason = '';
        this.areaFlag = false;
      }else if(this.index == 3) {
        this.placeholder = '输入禁言7天原因';
        this.reason = '';
        this.areaFlag = true;
      }else if(this.index == 4) {
        this.placeholder = '输入永久禁言原因';
        this.reason = '';
        this.areaFlag = true;
      }else if(this.index == 5) {
        this.reason = '';
        this.areaFlag = false;
      }
    },
    addSee(row) {
      console.log(row)
      let url = '/admin/user/user_info';
      let data = { user_id: row.id };
      this.$request.post(url,data).then( res => {
        console.log(res)
        if(res.data.code == '0000') {
          this.detail = res.data.data;
          this.moreUsermaAlert = true;
          console.log(res.data.data)
        }
      })
    },
    reset() {     //重置
      this.tableData.nickname = '';
      this.tableData.sex = '';
      this.tableData.age = '';
      this.tableData.start = '';
      this.tableData.expert = '';
      this.tableData.page = 1;
      this.currentPage4 = 1;
      this.getList();
    },
    query() {      //查询
      this.tableData.page = 1;
      this.currentPage4 = 1;
      let time = this.dataTime;
      console.log('2wwwwwwwwwwwwwwwwwwwwwww',time)
      if(time instanceof Array) {
        if(time.length > 0) {
          this.tableData.start = Number(time[0]/1000); 
          this.tableData.end = Number(time[1]/1000); 
        }
      }
      
      
      // console.log(this.tableData)
      
      this.getList();
      
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage4 = val;
      this.tableData.page = val;
      this.getList();
    },
  },
  
}
</script>
<style scoped lang="less">
  .articlelist_lable {
    min-width: 25%;
    white-space: nowrap;
  }
  .articlelist_query {
    margin-right: 100px;
    height: 100px;
  }
  .user_img {
    width: 50px;
    height: 50px;
  }
  .user_dialog_desc {
    height: 60px;
    border-bottom: 1px solid #999;
  }
  .user_dialog_quan {
    height: 100px;
  }
  .text_area {
    width: 350px;
    height: 50px;
    color: #000;
    font-size: 15px;
    padding: 5px;
  }
</style>

